const DB = require('../../../utils/db')
// 引入jwt token工具
const JwtUtil = require('../../../utils/jwt')
/**
 * GET
 * 根据自己的id,获取群聊
 */

module.exports = async (ctx) => {
  // 获取token
  let token = ctx.request.header.authorization
  let jwt = new JwtUtil(token)
  // 用token获取到userid
  let userid = jwt.verifyToken()
  const groupList = await DB.query(
    `select ug.groupid, g.groupName, g.introduction, g.announcement, g.lord from user_group ug join \`group\` g on ug.groupid = g.groupid where ug.userid='${userid}';`
  )
  console.log(groupList,909011)
  ctx.body = {
    code: 0,
    data: groupList,
  }
}
